import React, {Component} from 'react'
import {ListComponent} from '../../../components'
import UpdateUserPage from './Update'
import { Modal } from 'antd';

export default class DownListComponent extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            rowObj: {},
            isAdd: true
        };
        //行操作列表
        this.rowOperation = [
            {
                handleName: 'rowClick',
                showName: '行单击选择事件'
            }
        ];
        //header 操作列表
        this.headerOperation = [
            {
                handleName: 'addUser',
                showName: '新增',
                iconClass: 'plus'
            },{
                handleName: 'edit',
                showName: '修改',
                iconClass: 'edit'
            },{
                handleName: 'delete',
                showName: '删除',
                iconClass: 'delete'
            }
        ];
        //table列表展示列配置
        //showName、columnName 必有属性， columnWidth 可选，默认100, columnHidden: true 列隐藏（用于列配置显示隐藏）, foreverHidden: true 列永久隐藏
        this.tableColumn = {
            data: [
                {
                    showName: 'id',
                    columnName: 'userId',
                    columnHidden:true,
                    foreverHidden: true
                },{
                    showName: '登录账户名',
                    columnName: 'loginName',
                    columnWidth: 130
                },{
                    showName: '人员姓名',
                    columnName: 'userName'
                },{
                    showName: '邮件地址',
                    columnName: 'email',
                    columnHidden: true
                },{
                    showName: '座机号',
                    columnName: 'phone'
                },{
                    showName: '手机号',
                    columnName: 'mobile',
                    columnWidth: 130
                },{
                    showName: '是否可登录',
                    columnName: 'loginFlag',
                    showOption:[//页面显示配置
                        {
                            optionKey:'1',
                            optionShow:'是'
                        },{
                            optionKey:'0',
                            optionShow:'否'
                        }
                    ]
                },{
                    showName: '创建人',
                    columnName: 'createBy'
                },{
                    showName: '创建时间',
                    columnName: 'gmtCreateStr'
                },{
                    showName: '更新人',
                    columnName: 'lastModifiedBy'
                },{
                    showName: '更新时间',
                    columnName: 'gmtModified'
                }
            ]
        };
    }
    rowHandles = (strHandles, rowObj) => {
        if(strHandles === 'edit'){
            this.editHandle(rowObj);
        }else if(strHandles === 'delete'){
            this.deleteHandle(rowObj);
        }else if(strHandles === 'addUser'){
            this.addUserHandle();
        }else if(strHandles == 'rowClick'){
            this.rowClickHandle(rowObj);
        }
    }
    // 增加用户
    addUserHandle = () => {
        this.refs.updateUser.addUserHandle();
    }
    editHandle = (rowObj) => {
        this.refs.updateUser.getFormData[1]={
            type : 'input',
            showName : '登录用户名',
            name : 'loginName',
            initialValue : '',
            required:'required',
            disable: true
        };
        if(rowObj.length == 0){
            Modal.error({
                title: '错误提示',
                content: '请选择一条数据',
            });
        }else if(rowObj.length > 1){
            Modal.error({
                title: '错误提示',
                content: '只能选择一条数据',
            });
        }else{
            this.refs.updateUser.editHandle(rowObj[0].data);
        }
    }

    deleteHandle = (rowObj) => {
        if(rowObj.length == 0){
            Modal.error({
                title: '错误提示',
                content: '请选择一条数据',
            });
        }else if(rowObj.length > 1){
            Modal.error({
                title: '错误提示',
                content: '只能选择一条数据',
            });
        }else{
            this.refs.updateUser.deleteHandle(rowObj[0].data)
        }
    }

    rowClickHandle = (rowObj) => {
        console.log("单行选择rowObj===", JSON.stringify(rowObj));
    }
    refreshHandle = () => {
        this.refs.listComponent.refreshHandle();
    }

    render() {
        return (
            <div>
                <ListComponent
                    ref = "listComponent"
                    url = '/base/auth/user/list'
                    searchCondition={this.props.searchCondition}
                    tableColumnData = {this.tableColumn}
                    headerOperation = {this.headerOperation}
                    rowOperation = {this.rowOperation}
                    rowHandles = {this.rowHandles}
                    isRowSingle = "true"
                    subtractHeight = '0'
                    subtractWidth ='0'
                />

                <UpdateUserPage
                    ref="updateUser"
                    refreshHandle = {this.refreshHandle}
                />
            </div>
        );
    }
}
